/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jmooc.dao.jpa;

import com.jmooc.dao.UserCertificationDao;
import com.jmooc.entity.User;
import com.jmooc.entity.UserCertification;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Group
 */
@Stateless
public class JpaUserCertification implements UserCertificationDao {
    
    @PersistenceContext
    private EntityManager em;

    @Override
    public List<UserCertification> getAllByUser(User user) {
        return em.createQuery("SELECT uc FROM UserCertification uc WHERE uc.user = :u").setParameter("u", user).getResultList();
    }

    @Override
    public void create(UserCertification userCertification) {
        em.persist(userCertification);
    }
    
    @Override
    public UserCertification getById(Long id) {
        return (UserCertification) em.createQuery("SELECT uc FROM UserCertification uc WHERE uc.id = :i").setParameter("i", id).getSingleResult();
    }
}